package com.xzjie.web.core.listener;

import org.apache.shiro.session.Session;
import org.apache.shiro.session.SessionListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.xzjie.core.shiro.session.ShiroSessionRepository;

public class CustomSessionListener implements SessionListener {

	private static final Logger logger = LoggerFactory.getLogger(CustomSessionListener.class);

	private ShiroSessionRepository shiroSessionRepository;

	@Override
	public void onStart(Session session) {
		StringBuilder sb = new StringBuilder();
		sb.append("\r\n==============================\r\n");
		sb.append("\r\n    on start session listener \r\n");
		sb.append("\r\n==============================\r\n");
		
		logger.info(sb.toString());
	}

	@Override
	public void onStop(Session session) {
		StringBuilder sb = new StringBuilder();
		sb.append("\r\n=============================\r\n");
		sb.append("\r\n    on stop session listener \r\n");
		sb.append("\r\n=============================\r\n");
		
		logger.info(sb.toString());
	}

	@Override
	public void onExpiration(Session session) {
		shiroSessionRepository.deleteSession(session.getId());
	}

	public ShiroSessionRepository getShiroSessionRepository() {
		return shiroSessionRepository;
	}

	public void setShiroSessionRepository(ShiroSessionRepository shiroSessionRepository) {
		this.shiroSessionRepository = shiroSessionRepository;
	}

}
